﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web.Services.Protocols;
using Microsoft.SqlServer.ReportingServices2005.Execution;
using System.IO;

namespace DGTestApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = new System.Net.NetworkCredential("administrator", "stb2007");
            this.reportViewer1.ServerReport.ReportPath = "/BillingReports/InvoiceDetails";
            reportViewer1.RefreshReport();
            // ListRenderingExtensions();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //// TODO: This line of code loads data into the 'BillingDataSet.ClientsView' table. You can move, or remove it, as needed.
            //this.ClientsViewTableAdapter.Fill(this.BillingDataSet.ClientsView);

            //Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("Billing", ClientsViewBindingSource);
            //reportViewer1.LocalReport.DataSources.Clear();
            //reportViewer1.LocalReport.DataSources.Add(rds);
            //this.reportViewer1.RefreshReport();
        }

        private void reportViewer1_DoubleClick(object sender, EventArgs e)
        {
        }

        private void btExport_Click(object sender, EventArgs e)
        {

        }

        void DoExport()
        {
            //Warning[] warnings;
            //string[] streamids;
            //string mimeType;
            //string encoding;
            //string extension;

            //ReportExecutionService rs = new ReportExecutionService();

            //// Set the base Web service URL of the source server
            //rs.Url = "http://localhost/reportserver/ReportExecution2005.asmx";

            //rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

            //ExecutionInfo eInf = rs.LoadReport("/Test/Report1", null);

            //eInf = rs.GetExecutionInfo();


            //localhost.ReportingService s = new DGTestApp.localhost.ReportingService();

            //s.Credentials = rs.Credentials;

            //byte[] rDef = s.GetReportDefinition("/Test/Report1");

            //localhost.DataSource[] dss = s.GetReportDataSources("/Test/Report1");


            //byte[] report = rs.Render(cbxExtensions.SelectedItem.ToString(), null, out extension, out mimeType, out encoding, out warnings, out streamids);


            ////MemoryStream mStream = new MemoryStream(report);
            ////mStream.Seek(0, SeekOrigin.Begin);

            ////webBrowser1.DocumentText = System.Text.Encoding.UTF8.GetString(report);

            ////mStream.Close();

        }

        void ListRenderingExtensions()
        {
            //ReportExecutionService rs = new ReportExecutionService();

            //// Set the base Web service URL of the source server
            //rs.Url = "http://localhost/reportserver/ReportExecution2005.asmx";

            //rs.Credentials = System.Net.CredentialCache.DefaultCredentials;


            //Extension[] extensions = null;

            //// Retrieve a list of all renderingextensions. 
            //try
            //{
            //    extensions = rs.ListRenderingExtensions();

            //    if (extensions != null)
            //    {
            //        foreach (Extension extension in extensions)
            //        {
            //            cbxExtensions.Items.Add(extension.Name);
            //        }
            //    }
            //}

            //catch (SoapException e)
            //{
            //    MessageBox.Show(e.Detail.OuterXml);
            //}
        }

        private void button1_Click(object sender, EventArgs e)
        {
            btExport_Click(sender, e);
        }

    }
}
